extends Node
# 教程参考BV1DH4y1S7jJ （但路径用的res）
# 新教程 BV1MH4y1L79W
var level_save:SavedLevel = SavedLevel.new()

#保存已经看起来没有问题了
func save_level(file_path:String):
	var level:Node3D = get_tree().current_scene
	var player:Player = level.get_node("Entities/Player")
	if player:
		level_save.camera_rotation_state = player.camera_rotation_state
		level_save.camera_distance = player.camera_distance
	level_save.level.pack(level)  
	ResourceSaver.save(level_save,file_path) 

# 加载的话，load一步没有成功的样子
func load_level(file_path:String):
	level_save = load(file_path) as SavedLevel # 这一步没成功
	if level_save: #找到了才操作，增加鲁棒性
		var tree:SceneTree = get_tree()
		tree.change_scene_to_packed(level_save.level)
		await tree.node_added
		var level:Node3D = get_tree().current_scene
		var player:CharacterBody3D = level.get_node("Entities/Player")
		await player.ready
		player.camera_rotation_state = level_save.camera_rotation_state
		player.camera_distance = level_save.camera_distance
	
# Resource存档是可能被下毒的……但是要有功能性的话好像又非resource不可？
